package wnhz.com.business.groupshop.ui;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.WindowManager;

import com.yanzhenjie.recyclerview.swipe.SwipeMenu;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuBridge;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuCreator;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuItem;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuItemClickListener;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import wnhz.com.business.R;
import wnhz.com.business.base.BaseActivity;
import wnhz.com.business.base.BaseRVAdapter;
import wnhz.com.business.base.BaseViewHolder;
import wnhz.com.business.groupshop.adapter.AttentionAdapter;
import wnhz.com.business.impl.ActionBarClickListener;
import wnhz.com.business.view.TranslucentActionBar;

/**
 * 我的关注
 */
public class MyAttentionActivity extends BaseActivity implements ActionBarClickListener {


    @BindView(R.id.actionbar)
    TranslucentActionBar actionbar;
    @BindView(R.id.recycler_arrention)
    SwipeMenuRecyclerView recyclerArrention;

    private List<String> itemdata = new ArrayList<>();

    private AttentionAdapter attentionAdapter;



    public static Intent createIntent(Context context) {
        Intent intent = new Intent(context, MyAttentionActivity.class);
        return intent;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_attention);
        ButterKnife.bind(this);

        actionbar.setData("关注", R.drawable.ic_lefft_white, null, 0, null, 0, this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            actionbar.setStatusBarHeight(getStatusBarHeight());
        }

        initview();
        setRecyclerArrention();
        cancel();
    }

    private void initview() {
        recyclerArrention.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        for (int i = 0; i < 5; i++) {
            itemdata.add("test" + i);
        }

    }

    //加载数据
    private void setRecyclerArrention() {
        attentionAdapter = new AttentionAdapter(itemdata);
        recyclerArrention.setAdapter(attentionAdapter);
    }

    //侧滑取消关注
    public void cancel()
    {
        //菜单布局
        recyclerArrention.setSwipeMenuCreator(new SwipeMenuCreator() {
            @Override
            public void onCreateMenu(SwipeMenu swipeLeftMenu, SwipeMenu swipeRightMenu, int viewType) {
                SwipeMenuItem deleteItem = new SwipeMenuItem(MyAttentionActivity.this)
                        .setText("取消\n关注")
                        .setTextSize(14)
                        .setWidth(200)
                        .setHeight(WindowManager.LayoutParams.MATCH_PARENT)
                        .setTextColor(getResources().getColor(R.color.white))
                        .setBackgroundColor(getResources().getColor(R.color.red255));
                swipeRightMenu.addMenuItem(deleteItem); // 在Item右侧添加一个菜单。

            }
        });
        //菜单点击事件
        recyclerArrention.setSwipeMenuItemClickListener(new SwipeMenuItemClickListener() {
            @Override
            public void onItemClick(SwipeMenuBridge menuBridge) {
                menuBridge.closeMenu();
                int direction = menuBridge.getDirection(); // 左侧还是右侧菜单。
                if (direction == SwipeMenuRecyclerView.RIGHT_DIRECTION) {
                    int position  =menuBridge.getAdapterPosition();
                    itemdata.remove(position);
                    attentionAdapter.notifyItemRemoved(position);
                }
            }
        });
    }

    @Override
    public void onLeftClick() {
        finish();
    }

    @Override
    public void onRightClick() {
    }

    @Override
    public void onEditTextClick() {

    }
}
